package com.boarsoft.message.rocketmq;

import java.io.Closeable;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.MQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RocketMQProducer implements Closeable {
	private static final Logger log = LoggerFactory.getLogger(RocketMQProducer.class);
	/** */
	protected MQProducer producer;

	@Override
	public void close() {
		producer.shutdown();
		producer = null;
	}

	public void init() {
		try {
			producer.start();
		} catch (MQClientException e) {
			log.error("Error on start RocketMQ producer", e);
		}
	}

	public SendResult send(Message msg) throws Exception {
		return producer.send(msg);
	}

	public MQProducer getProducer() {
		return producer;
	}

	public void setProducer(MQProducer producer) {
		this.producer = producer;
	}
}
